home *** CD-ROM | disk | FTP | other *** search
/ Chip 2004 July / CMCD0704.ISO / Software / Shareware / Utilitare / Girder / girder331c.exe / {app} / help / girder.php next >
PHP Script  |  2002-10-22  |  3KB  |  112 lines

  1. <?php
  2.     
  3.     // need this on XS-HTTPD.
  4.   header ("Expires: Mon, 26 Jul 1997 05:00:00 GMT");    // Date in the past
  5.   header ("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
  6.                                                       // always modified
  7.     header ("Cache-Control: no-cache, must-revalidate");  // HTTP/1.1
  8.     header ("Pragma: no-cache");                          // HTTP/1.0
  9.     
  10.  
  11. function sendMsg($args) {
  12.  
  13.     $fp = fsockopen($args["host"],$args["port"], &$errno, &$errstr);
  14.     
  15.     if (!$fp) { //Something didn't work....
  16.         echo "ERROR: $errno - $errstr\n";
  17.         return FALSE;
  18.  
  19.     } else {
  20.  
  21.         // First wake up the server, for security reasons it does not
  22.         // respond by it self it needs this string, why this odd word ?
  23.         // well if someone is scanning ports "connect" would be very obvious
  24.         // this one you'd never guess :-)
  25.         
  26.       fputs($fp, "quintessence\n\r");
  27.         
  28.         // The server now returns a cookie, the protocol works like the
  29.         // APOP protocol. The server gives you a cookie you add :<password>
  30.         // calculate the md5 digest out of this and send it back
  31.         // if the digests match you are in.
  32.         // We do this so that noone can listen in on our password exchange
  33.         // much safer then plain text.
  34.         
  35.         $cookie = fgets($fp, 400);        
  36.         
  37.         // Trim all enters and whitespaces off
  38.         $cookie = trim($cookie);
  39.         
  40.         // Combine the token <cookie>:$args[pword]
  41.         $token = $cookie . ":" . $args["password"];
  42.         
  43.         // Calculate the digest
  44.         $digest = md5($token);
  45.         
  46.         // add the enters 
  47.         $digest = $digest . "\n";
  48.                 
  49.         // Send it to the server        
  50.         fputs($fp, $digest );
  51.         
  52.         // Get the answer
  53.         $res = fgets($fp, 400);
  54.         
  55.         // If the password was correct and you are allowed to connect 
  56.         // to the server, you'll get "accept" 
  57.         if ( trim($res) != "accept" ) 
  58.         {
  59.              fclose($fp);
  60.              return FALSE;
  61.         }
  62.         
  63.         if ( $args["payload"] <> "" )
  64.         {
  65.                 fputs($fp, "payload ".$args["payload"]."\n");        
  66.         }
  67.         // now just pipe those commands to the server
  68.         fputs($fp, $args["command"]."\n");
  69.         
  70.         // tell the server that we are done nicely.
  71.         fputs($fp, "close\n");
  72.         
  73.       fclose($fp);
  74.             
  75.         return TRUE;
  76.     }
  77. }
  78. ?>
  79. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
  80.  
  81. <html>
  82. <head>
  83. <title>Page title</title>
  84. </head>
  85. <body>
  86.  
  87. <?php
  88.     if ( $HTTP_POST_VARS['send'] <> "" )
  89.     {      
  90.       if ( sendMsg($HTTP_POST_VARS) == TRUE ) 
  91.         {
  92.               echo "command sent succesfully<br>";
  93.         }
  94.         else
  95.         {
  96.             echo "Connection failed. (bad password/connection blocked)<br>"    ;    
  97.         }
  98.     }
  99. ?>
  100. <form action="msggirder.php" method="post">
  101. <table>
  102. <tr><td>Hostname</td><td><input type=text name="host" value="<?php echo $HTTP_POST_VARS["host"]; ?>"></td></tr>
  103. <tr><td>Port</td><td><input type=text name="port" value="<?php echo $HTTP_POST_VARS["port"]; ?>"></td></tr>
  104. <tr><td>Password</td><td><input type=password name="password" value="<?php echo $HTTP_POST_VARS["password"]; ?>"></td></tr>
  105. <tr><td>Eventstring</td><td><input type=text name="command" value="<?php echo $HTTP_POST_VARS["command"]; ?>"></td></tr>
  106. <tr><td>Payload</td><td><input type=text name="payload" value="<?php echo $HTTP_POST_VARS["payload"]; ?>"></td></tr>
  107. <tr><td colspan=2><input type=submit name="send" value="go!"></td></tr>
  108. </table>
  109. <form>
  110. </body>
  111. </html>
  112.